package reflectx

import (
	"gitee.com/zhongguo168a/gocodes/datax/schemax"
)

type ClassDeclRef struct {
}

func (desc *ClassDeclRef) RefNew() IRefObject {
	return &schemax.ClassDecl{}
}

func (desc *ClassDeclRef) RefType() string {
	return "classdecl"
}

func (desc *ClassDeclRef) RefHas(field string) bool {
	switch field {
	case "Name":
		return true
	case "Parent":
		return true
	case "Fields":
		return true
	case "Namespace":
		return true
	case "Tags":
		return true

	}
	return false
}

func (desc *ClassDeclRef) RefGet(target IRefObject, key string) (interface{}, bool) {
	obj := target.(*schemax.ClassDecl)
	switch key {
	case "Name":
		return obj.Name, false
	case "Parent":
		return obj.Parent, false
	case "Fields":
		return obj.Fields, false
	case "Namespace":
		return obj.Namespace, false
	case "Tags":
		return obj.Tags, false
	}
	return nil, true
}
func (desc *ClassDeclRef) RefSet(target IRefObject, key string, val interface{}) {
	obj := target.(*schemax.ClassDecl)
	switch key {
	case "Name":
		obj.Name = val.(string)
	case "Parent":
		obj.Parent = val.(string)
	case "Fields":
		obj.Fields = val.([]*schemax.Field)
	case "Namespace":
		obj.Namespace = val.(string)
	case "Tags":
		obj.Tags = val.(map[string]string)
	}
	return
}
func (desc *ClassDeclRef) RefSliceLength(target IRefObject, key string) int {
	obj := target.(*schemax.ClassDecl)
	switch key {
	case "Fields":
		return len(obj.Fields)
	}
	return 0
}
func (desc *ClassDeclRef) RefSliceGet(target IRefObject, key string, index int) (interface{}, bool) {
	obj := target.(*schemax.ClassDecl)
	switch key {
	case "Fields":
		val := obj.Fields[index]
		return val, val == nil
	}
	return nil, true
}
func (desc *ClassDeclRef) RefSliceSet(target IRefObject, key string, index int, val interface{}) {
	obj := target.(*schemax.ClassDecl)
	switch key {
	case "Fields":
		obj.Fields[index] = val.(*schemax.Field)
	}
	return
}

func (desc *ClassDeclRef) RefSliceNew(field string, len int, cap int) interface{} {
	switch field {
	case "Fields":
		return make([]*schemax.Field, len, cap)
	}
	return nil
}

func (ref *ClassDeclRef) RefMapGet(obj IRefObject, field string, key string) (interface{}, bool) {
	target := obj.(*schemax.ClassDecl)
	_ = target
	switch field {
	case "Tags":
		val := target.Tags[key]
		return val, false

	}

	return nil, false
}

func (ref *ClassDeclRef) RefMapSet(obj IRefObject, field string, key string, val interface{}) {
	target := obj.(*schemax.ClassDecl)
	_ = target
	switch field {
	case "Tags":
		if target.Tags == nil {
			target.Tags = map[string]string{}
		}
		target.Tags[key] = val.(string)
	}

}

func (ref *ClassDeclRef) RefMapNew(field string) interface{} {
	switch field {
	case "Tags":
		return make(map[string]string)

	}

	return nil
}

func (ref *ClassDeclRef) RefMapKeys(obj IRefObject, field string) (keys []string) {
	target := obj.(*schemax.ClassDecl)
	switch field {
	case "Tags":
		for key := range target.Tags {
			keys = append(keys, key)
		}
		return
	}

	return
}
